package com.boyadegroot.divelog.ui.diver.tabs;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.GridLayout;
import android.widget.TextView;

import com.boyadegroot.divelog.R;
import com.boyadegroot.divelog.models.Dive;
import com.boyadegroot.divelog.models.DiveSite;
import com.boyadegroot.divelog.utilities.DateUtils;

public class DiverStat extends GridLayout {

    private TextView mStatName;
    private TextView mStatValue;
    private TextView mDiveSite;
    private TextView mDiveDate;

    public DiverStat(Context context) {
        super(context);
        initViews(context);
    }

    public DiverStat(Context context, AttributeSet attrs) {
        super(context, attrs);
        initViews(context);
    }

    private void initViews(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.view_statistic, this);
        mStatName = (TextView) view.findViewById(R.id.stat_name);
        mStatValue = (TextView) view.findViewById(R.id.stat_value);
        mDiveSite = (TextView) view.findViewById(R.id.stat_divesite);
        mDiveDate = (TextView) view.findViewById(R.id.stat_divedate);
    }

    public void setDiveStat(Dive dive, String statName, String statValue) {
        mStatName.setText(statName);
        if (dive != null) {
            DiveSite site = dive.getSite();
            if (site != null) {
                mDiveSite.setText(site.getName());
            }
            long startTime = dive.getStartTime();
            if (startTime != 0) {
                mDiveDate.setText(DateUtils.getLongDateString(startTime));
            }
        }
        mStatValue.setText(statValue);
    }
}
